﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;

namespace zielonka.co.uk.extensions.system.data
{
    // Description: Clones a DataRow - including strongly typed DataRows.
    /*
        MyDataRow newDataRow = myDataRow.Clone<MyDataRow>(myDataRow.DataTable);
    */

    public static partial class DataRowExtensions
    {
        /// <summary>
        /// Creates a cloned and detached copy of a DataRow instance
        /// </summary>
        /// <typeparam name="T">The type of the DataRow if strongly typed</typeparam>
        /// <returns>
        /// An instance of the new DataRow
        /// </returns>
        public static T Clone<T>(this DataRow dataRow, DataTable parentTable)
            where T : DataRow
        {
            T clonedRow = (T)parentTable.NewRow();
            clonedRow.ItemArray = dataRow.ItemArray;
            return clonedRow;
        }
    }
}
